<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class BusForm extends Base
{
    protected $insert = ['addtime','pass'];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }
    public function getAddtimeTextAttr($value, $data){
        return date('Y-m-d H:i:s', $data['addtime']);
    }

    public function getImageTextAttr($value,$data){
        return $data['image'] ? cdnurl($data['image'],true) : "";
    }
    public function getLevelTextAttr($value,$data){
        return (new \app\common\model\BusLevel())->where(['id' => $data['level_id']])->value('title');
    }
    public function setPassArrt($value){
        return StrMD5($value);
    }
    public function getIsStateTextAttr($value,$data){
        $arr = ['正常','封禁'];
        return $arr[$data['is_state']];
    }
    public function getCompanyTitleAttr($value,$data){
        return $data['company_id'] == 0 ? '' : (new \app\common\model\Company())->where(['id' => $data['company_id']])->value('title');
    }

    public function getAgentTitleAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('nickname');
    }
    public function getProvinceAttr($value,$data){
        return (new \app\common\model\City())->where(['id' => $data['province_id']])->value(['ShortName']);
    }
    public function getAreaAttr($value,$data){
        return (new \app\common\model\City())->where(['id' => $data['area_id']])->value(['ShortName']);
    }
    public function getCityAttr($value,$data){
        return (new \app\common\model\City())->where(['id' => $data['city_id']])->value(['ShortName']);
    }
}
